<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

session_start();

class Partnership extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		
		$this->load->helper(array('url','cookie','html','language','security'));
		$this->load->library(array('parser','session','user_agent','upload','encrypt'));
		
		$uagent = do_hash($this->agent->browser());
		$platform = do_hash($this->agent->platform());
		
		if($this->agent->is_browser())
		{
			if(($this->input->cookie('dsn_agent') != $uagent) OR ($this->input->cookie('dsn_platform') != $platform))
			{
				redirect(base_url('error/uagent'));
				exit(0);
			}
		}else{
			redirect(base_url('error/uagent'));
			exit(0);
		}
		
		require('./lib/src/skey.php');
		
		if($lvl != 2)
		{
			redirect(base_url('main/login.html'));
			exit(0);
		}
		
		$this->load->model('Partner_model','partnermodel',TRUE);
			
		function pesan($pesan, $url)
		{
			echo "
				<script type='text/javascript'>
					alert('$pesan');
					window.location.href='$url';
				</script>
				<noscript>
					<center>
						$pesan <br />
						<a href='$url'>Lanjutkan &gt;&gt;</a>
					</center>
				</noscript>
			";
		}
		
		
	}
	   
	public function index()
	{
		$this->load->view('main/login');
	}
	
	
	public function usahabaru()
	{
		require('./lib/src/skey.php');
		
		$nama = $this->input->post('nama');
		$kategori = $this->input->post('kategori');
		$pemilik = $this->input->post('pemilik');
		$deskripsi = $this->input->post('deskripsi');
		$alamat = $this->input->post('alamat');
		$kota = $this->input->post('kota');
		$situs = prep_url(strtolower($this->input->post('situs')));
		$email = $this->input->post('email');
		$phone = $this->input->post('phone');
		$vphone = $this->input->post('vphone');
		$gambar = '';
		
		$config['upload_path'] = './uploads/perusahaan/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '1000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);
		
		$insert = FALSE;
		
		if((!empty($nama)) && (!empty($kategori)) && (!empty($pemilik)) && (!empty($alamat)) && (!empty($kota)))
		{
			if(!empty($_FILES['logo']['name'])){
				if ($this->upload->do_upload('logo')){
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/perusahaan/baru'));
					exit(0);
				}
			}
			
			$data = array('idperusahaan' => '','idkategori' => $kategori,'uid' => $uid,'nama'=>$nama,'pemilik'=>$pemilik,'alamat'=>$alamat,'kota' => $kota, 'situs'=>$situs, 'email'=>$email,'telp'=>$phone,'telpv'=>$vphone,'logo' => $gambar);
			
			$insert = $this->partnermodel->set_perusahaan($data);
			
			if($insert === TRUE){
				pesan('Berhasil Menambah Data baru',base_url('partner/perusahaan'));
			}else{
				pesan('Gagal Menambah Data',base_url('partner/perusahaan'));
			}
			
		}else{
			pesan('Data Tidak Lengkap',base_url('partner/perusahaan/baru'));
		}
		
	}
	
	public function updateusaha(){
		
		require('./lib/src/skey.php');
		
		$idc = $this->input->post('idc');
		$nama = $this->input->post('nama');
		$kategori = $this->input->post('kategori');
		$pemilik = $this->input->post('pemilik');
		$deskripsi = $this->input->post('deskripsi');
		$alamat = $this->input->post('alamat');
		$kota = $this->input->post('kota');
		$situs = prep_url(strtolower($this->input->post('situs')));
		$email = $this->input->post('email');
		$phone = $this->input->post('phone');
		$vphone = $this->input->post('vphone');
		$gambar = $this->input->post('oldgambar');
		$oldgambar = $gambar;
		$deloldgambar = FALSE;
		
		$config['upload_path'] = './uploads/perusahaan/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '1000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);
		
		$update = FALSE;
		
		if((!empty ($idc)) && (!empty($nama)) && (!empty($kategori)) && (!empty($pemilik)) && (!empty($alamat)) && (!empty($kota)))
		{
			if(! empty($_FILES['logo']['name']))
				{
					if ($this->upload->do_upload('logo'))
					{
						$udata = $this->upload->data();
						$gambar = $udata['file_name'];
						if(! empty($oldgambar)) { $deloldgambar = TRUE; }
					}else{
						pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/perusahaan/edit?idc='.$idc));
						exit(0);
					}
				}
				
				$data = array('idkategori' => $kategori,'nama' => $nama,'pemilik' => $pemilik,'deskripsi' => $deskripsi,'alamat'=>$alamat,'kota' => $kota, 'situs'=>$situs, 'email' => $email,'telp' => $phone,'telpv' => $vphone, 'logo' => $gambar);
				$update = $this->partnermodel->update_perusahaan($data,$idc,$uid);
			
		}else{
			pesan('Data Tidak lengkap',base_url('partner/perusahaan'));
			exit(0);
		}
		
		if($update === TRUE)
		{
			if($deloldgambar == TRUE)
			{
				unlink('./uploads/perusahaan/'.$oldgambar);
			}
			pesan('Sukses Memperbaharui Data',base_url('partner/perusahaan'));
		}
		else
		{
			pesan('Gagal Memperbaharui Data',base_url('partner/perusahaan'));
		}
	}
	
	public function hapususaha()
	{
		require('./lib/src/skey.php');
		
		$idusaha = $this->input->get('idc');
		$gambar = $this->partnermodel->get_data_single('logo','dn_company','idperusahaan',$idusaha);
		
		if($idusaha === 1)
		{
			$hapus = FALSE;
		}
		else
		{
			$hapus = $this->partnermodel->del_perusahaan($idusaha,$uid);
		}
	
		if($hapus == TRUE)
		{
			if( ! empty($gambar))
			{
				unlink('./uploads/perusahaan/'.$gambar);
			}
			pesan('Berhasil Menghapus Data',base_url('partner/perusahaan'));
		}
		else
		{
			pesan('Gagal Menghapus Data',base_url('partner/perusahaan'));
		}
	}
	
	public function produkbaru()
	{
		include "./lib/src/skey.php";
		
		$nama = $this->input->post('nama');
		$deskripsi = $this->input->post('deskripsi');
		$idusaha = $this->input->post('perusahaan');
		
		$config['upload_path'] = './uploads/produk/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '1000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);

		$gambar = "";
		$insert = FALSE;
		
		if((!empty($nama)) && (!empty($deskripsi)))
		{
			$cekPemilikUsaha = $this->partnermodel->cek_pemilik_usaha($idusaha,$uid);
			if($cekPemilikUsaha !== TRUE)
			{
				pesan('Tampaknya terjadi kesalahan',base_url('partner/produk/baru'));
				exit(0);
			}
			
			if(!empty($_FILES['gambar']['name']))
			{
				if ($this->upload->do_upload('gambar')){
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/produk/baru'));
					exit(0);
				}
			}
			
			$data = array('idproduk' => '', 'idperusahaan'=>$idusaha,'nama'=>$nama,'deskripsi'=>$deskripsi,'gambar'=>$gambar);
			$insert = $this->partnermodel->set_produk($data);
			
		}else{
			pesan('Data Tidak Lengkap',base_url('partner/produk/baru'));
		}
		
		if($insert === TRUE)
		{
			pesan('Sukses Menambah Data',base_url('partner/produk/'));
		}
		else
		{
			pesan('Tampaknya terjadi kesalahan',base_url('partner/produk/baru'));
		}
		
	}
	
	public function updateproduk()
	{
		include "./lib/src/skey.php";
		
		$nama = $this->input->post('nama');
		$deskripsi = $this->input->post('deskripsi');
		$idusaha = $this->input->post('perusahaan');
		$pid = $this->input->post('pid');
		$gambar = $this->input->post('oldgambar');
		$oldgambar = $gambar;
		$deloldgambar = FALSE;
		
		$update = FALSE;
		
		$config['upload_path'] = './uploads/produk/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '1000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);
		
		if((!empty ($pid)) && (!empty($nama)) && (!empty($deskripsi)) )
		{
			
			$cekPemilikUsaha = $this->partnermodel->cek_pemilik_usaha($idusaha,$uid);
			if($cekPemilikUsaha !== TRUE)
			{
				pesan('Tampaknya terjadi kesalahan',base_url('partner/produk/edit?idp='.$pid));
				exit(0);
			}
			
			if(!empty($_FILES['gambar']['name']))
			{
				if ($this->upload->do_upload('gambar'))
				{
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
					
					$deloldgambar = TRUE;
					
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/produk/'));
					exit(0);
				}
			}
			
			$data = array('idperusahaan' => $idusaha, 'nama' => $nama, 'deskripsi' => $deskripsi,'gambar' =>$gambar);
			$update = $this->partnermodel->update_produk($data,$pid);		
			
		}else{
			pesan('Data Tidak lengkap',base_url('partner/produk'));
		}
		
		if($update === TRUE)
		{
			if(! empty($oldgambar) && ($deloldgambar === TRUE))
			{
				unlink('./uploads/produk/'.$oldgambar);
			}
			pesan('Sukses Memperbaharui Data',base_url('partner/produk'));
		}
		else
		{
			pesan('Gagal Memperbaharui Data',base_url('partner/produk'));
		}
	}
	
	public function hapusproduk()
	{
		include "./lib/src/skey.php";
		
		$idproduk = $this->input->get('idp');
		
		$idperusahaan = $this->partnermodel->get_data_single('idperusahaan','dn_product','idproduk',$idproduk);
		$gambar = $this->partnermodel->get_data_single('gambar','dn_product','idproduk',$idproduk);
		
		$cekUsaha = $this->partnermodel->cek_pemilik_usaha($idperusahaan,$uid);
		if($cekUsaha === TRUE)
		{
			$hapus = $this->partnermodel->del_produk($idproduk);
		}
		else
		{
			$hapus = FALSE;
		}
	
		if($hapus === TRUE)
		{
			if(! empty($gambar))
			{
				unlink('./uploads/produk/'.$gambar);
			}
			pesan('Berhasil Menghapus Data',base_url('partner/produk'));
		}else{
			pesan('Gagal Menghapus Data',base_url('partner/produk'));
		}
	}
	
	public function tambahloker()
	{
		include "./lib/src/skey.php";
		
		$posisi = $this->input->post('posisi');
		$idusaha = $this->input->post('perusahaan');
		$deskripsi = $this->input->post('deskripsi');
		$tipe = $this->input->post('tipe');
		$lokasi = $this->input->post('lokasi');
		$cara = $this->input->post('cara');
		$berakhir = $this->input->post('berakhir');
		
		
		$config['upload_path'] = './uploads/lowongan/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '10000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);

		$gambar = "";
		$insert = FALSE;
		
		if((!empty($posisi)) && (!empty($deskripsi)) && (!empty($tipe)) && (!empty($lokasi)) && (!empty($cara)) && (!empty($berakhir)))
		{
			
			$cekPemilikUsaha = $this->partnermodel->cek_pemilik_usaha($idusaha,$uid);
			if($cekPemilikUsaha !== TRUE)
			{
				pesan('Tampaknya terjadi kesalahan',base_url('partner/loker/baru'));
				exit(0);
			}
			
			if(!empty($_FILES['gambar']['name']))
			{
				if ($this->upload->do_upload('gambar'))
				{
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/loker/baru'));
					exit(0);
				}
			}
			
			$data = array('idjob'=>'','idperusahaan'=>$idusaha,'posisi'=>$posisi,'deskripsi'=>$deskripsi, 'tipe' => $tipe, 'lokasi' => $lokasi, 'cara' => $cara,'gambar'=>$gambar, 'berakhir'=>$berakhir);
			$insert = $this->partnermodel->setLoker($data);
			
		}else{
			pesan('Data Tidak Lengkap',base_url('partner/loker/baru'));
		}
		
		if($insert === TRUE)
		{
			pesan('Sukses Menambah Data',base_url('partner/loker/'));
		}
		else
		{
			pesan('Gagal menambah Data\nCoba lagi nanti',base_url('partner/loker/'));
		}
		
	}
	
	public function updateloker()
	{
		
		include "./lib/src/skey.php";
		
		$idl = $this->input->post('idl');
		$posisi = $this->input->post('posisi');
		$idusaha = $this->input->post('perusahaan');
		$deskripsi = $this->input->post('deskripsi');
		$tipe = $this->input->post('tipe');
		$lokasi = $this->input->post('lokasi');
		$cara = $this->input->post('cara');
		$berakhir = $this->input->post('berakhir');
		$gambar = $this->input->post('oldgambar');
		$oldgambar = $gambar;
		
		$deloldgambar = FALSE;
		$update = FALSE;
		
		$config['upload_path'] = './uploads/lowongan/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '10000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);
		
		if((!empty ($idl)) && (!empty($posisi)) && (!empty($deskripsi)) && (!empty($tipe)) && (!empty($cara)) && (!empty($lokasi)) && (!empty($berakhir)))
		{
			
			$cekPemilikUsaha = $this->partnermodel->cek_pemilik_usaha($idusaha,$uid);
			if($cekPemilikUsaha !== TRUE)
			{
				pesan('Tampaknya terjadi kesalahan',base_url('partner/loker/edit?idl='.$idl));
				exit(0);
			}
			
			if(!empty($_FILES['gambar']['name']))
			{
				if ($this->upload->do_upload('gambar'))
				{
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
					
					$deloldgambar = TRUE;
					
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/loker/edit'));
					exit(0);
				}
			}
			
			$data = array('idperusahaan' => $idusaha, 'posisi'=>$posisi,'deskripsi'=>$deskripsi,'tipe' => $tipe, 'lokasi' => $lokasi, 'cara' => $cara,'gambar'=>$gambar,'berakhir'=>$berakhir);
			$update = $this->partnermodel->update_loker($data,$idl);
			
		}else{
			pesan('Data Tidak lengkap',base_url('partner/loker'));
		}
		
		if($update === TRUE){
			if(! empty($oldgambar) && ($deloldgambar == TRUE))
			{
				unlink('./uploads/lowongan/'.$oldgambar);
			}
			pesan('Sukses Memperbaharui Data',base_url('partner/loker'));
		}else{
			pesan('Gagal Memperbaharui Data',base_url('partner/loker'));
		}
		
		
	}
	
	public function hapusloker()
	{
		
		include "./lib/src/skey.php";
		$idloker = $this->input->get('idl');
		
		$gambar = $this->partnermodel->get_data_single('gambar','dn_job','idjob',$idloker);
		$idusaha = $this->partnermodel->get_data_single('idperusahaan','dn_job','idjob',$idloker);
		
		
		$cekPemilikUsaha = $this->partnermodel->cek_pemilik_usaha($idusaha, $uid);
		
		if($cekPemilikUsaha === TRUE)
		{
			$hapus = $this->partnermodel->del_loker($idloker);
		}
		else
		{
			pesan('Tampaknya terjadi Kesalahan',base_url('partner/loker'));
		}
	
		if($hapus === TRUE)
		{
			if( ! empty($gambar))
			{
				unlink('./uploads/lowongan/'.$gambar);
			}
			pesan('Berhasil Menghapus Data',base_url('partner/loker'));
		}else{
			pesan('Gagal Menghapus Data',base_url('partner/loker'));
		}
	}
	
	public function promosibaru(){
		$judul = $this->input->post('judul');
		$promosi = $this->input->post('promosi');
		$berakhir = $this->input->post('berakhir');
		$idc = $this->input->post('idc');
		
		$gambar = "";
		$insert = false;
		
		if(empty($idc)){
			$idc = 1;
		}
		
		$config['upload_path'] = './uploads/promosi/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '1000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);

		
		
		if((!empty($judul)) && (!empty($promosi)))
		{
			if(!empty($_FILES['gambar']['name'])){
				if ($this->upload->do_upload('gambar'))
				{
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/promosi/baru'));
					exit(0);
				}
			}
			
			$data = array('idpromosi'=>'','idperusahaan'=>$idc,'judul'=>$judul,'promosi'=>$promosi,'gambar'=>$gambar,'berakhir'=>$berakhir);
			$this->adminmodel->setData('dn_promote',$data);
			pesan('Sukses Menambah Data',base_url('partner/promosi/'));
		}else{
			pesan('Data Tidak Lengkap',base_url('partner/promosi/baru'));
		}
		
	}
	
	public function updatepromosi(){
		$judul = $this->input->post('judul');
		$promosi = $this->input->post('promosi');
		$berakhir = $this->input->post('berakhir');
		$gambar = $this->input->post('oldgambar');
		$idp = $this->input->post('idp');
		
		$update = false;
		
		$config['upload_path'] = './uploads/promosi/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '1000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);
		
		if((!empty ($idp)) && (!empty($judul)) && (!empty($promosi)) && (!empty($berakhir))){
			
			if(!empty($_FILES['gambar']['name'])){
				if ($this->upload->do_upload('gambar')){
					if($gambar != ""){
						unlink('./uploads/promosi/'.$gambar);
					}
					
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
					
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/promosi/'));
					exit(0);
				}
			}
			$data = array('judul'=>$judul,'promosi'=>$promosi,'gambar'=>$gambar,'berakhir'=>$berakhir);
			$update = $this->adminmodel->updateData('dn_promote',$data,'idpromosi',$idp);
			
		}else{
			pesan('Data Tidak lengkap',base_url('partner/promosi'));
		}
		
		if($update == true){
			pesan('Sukses Memperbaharui Data',base_url('partner/promosi'));
		}else{
			pesan('Gagal Memperbaharui Data',base_url('partner/promosi'));
		}
		
		
	}
	
	public function hapuspromosi(){
		require "./lib/src/skey.php";
		
		$idp = $this->input->get('idp');
		$idusaha = $this->input->get('sec');
		
		$cekusaha = $this->partnermodel->cekUsaha('dn_promote','idpromosi',$idp,$idusaha,$uid);
		
		$gambar = $this->partnermodel->getDataSingle('gambar','dn_promote','idpromosi',$idp);
		if($cekusaha != FALSE){
			$hapus = $this->partnermodel->delData('dn_promote','idpromosi',$idp);
		}else{
			$hapus = FALSE;
		}
	
		if($hapus == TRUE){
			if(!empty($gambar)){
				unlink('./uploads/promosi/'.$gambar);
			}
			pesan('Berhasil Menghapus Data',base_url('partner/promosi'));
		}else{
			pesan('Gagal Menghapus Data',base_url('partner/promosi'));
		}
	}
	
	
	public function acarabaru()
	{
		$nama = $this->input->post('nama');
		$deskripsi = $this->input->post('deskripsi');
		$lokasi = $this->input->post('lokasi');
		$tanggal = $this->input->post('tanggal');
		
		$gambar = "";
		$insert = FALSE;
		
		include "./lib/src/skey.php";
		
		if(empty($uid) || ($lvl > 2))
		{
			pesan('Anda Tidak Memiliki Akses',base_url('partner/acara'));
			exit(0);
		}
		
		$config['upload_path'] = './uploads/acara/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '1000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);
		
		
		if((!empty($nama)) && (!empty($deskripsi)) && (!empty($lokasi)) && (!empty($tanggal)))
		{
			if(!empty($_FILES['gambar']['name']))
			{
				if ($this->upload->do_upload('gambar'))
				{
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/promosi/baru'));
					exit(0);
				}
			}
			
			$data = array('idacara'=>'','uid'=>$uid,'nama'=>$nama,'deskripsi'=>$deskripsi,'tanggal'=>$tanggal,'gambar'=>$gambar,'lokasi'=>$lokasi);
			$this->partnermodel->set_acara($data);
			pesan('Sukses Menambah Data',base_url('partner/acara/'));
		}else{
			pesan('Data Tidak Lengkap',base_url('partner/acara/baru'));
		}
		
	}
	
	public function updateacara()
	{
		$nama = $this->input->post('nama');
		$deskripsi = $this->input->post('deskripsi');
		$lokasi = $this->input->post('lokasi');
		$tanggal = $this->input->post('tanggal');
		$gambar = $this->input->post('oldgambar');
		$oldgambar = $gambar;
		$ida = $this->input->post('ida');
		
		$update = FALSE;
		$deloldgambar = FALSE;
		
		$config['upload_path'] = './uploads/acara/';
		$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
		$config['max_size']	= '1000';
		$config['max_width'] = '1000';
		$config['max_height'] = '1000';
		$config['max_filename'] = '100';
		$this->upload->initialize($config);
		
		if((!empty ($ida)) && (!empty($nama)) && (!empty($deskripsi)) && (!empty($lokasi)) && (!empty($tanggal)))
		{
			require "./lib/src/skey.php";
			if(!empty($_FILES['gambar']['name'])){
				if ($this->upload->do_upload('gambar'))
				{
					
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
					$deloldgambar = TRUE;
					
				}else{
					pesan('Terjadi Kesalahan saat mengunggah gambar\nPastikan ekstensi gambar diperbolehkan dan ukuran kurang dari 1 MB',base_url('partner/acara/'));
					exit(0);
				}
			}
			$data = array('nama'=>$nama,'deskripsi'=>$deskripsi,'tanggal'=>$tanggal,'gambar'=>$gambar,'lokasi'=>$lokasi);
			$update = $this->partnermodel->update_acara($data,$ida,$uid);
			
		}else{
			pesan('Data Tidak lengkap',base_url('partner/acara'));
		}
		
		if($update === TRUE)
		{
			if( ! empty($oldgambar) && ($deloldgambar == TRUE))
			{
				unlink('./uploads/acara/'.$oldgambar);
			}
			pesan('Sukses Memperbaharui Data',base_url('partner/acara'));
		}else{
			pesan('Gagal Memperbaharui Data',base_url('partner/acara'));
		}
	}
	
	public function hapusacara()
	{
		require "./lib/src/skey.php";
		$idacara = $this->input->get('ida');
		
		$gambar = $this->partnermodel->get_data_single('gambar','dn_event','idacara',$idacara);
		$hapus = $this->partnermodel->del_acara('dn_event','idacara',$idacara,'uid',$uid);
	
		if($hapus === TRUE)
		{
			if(!empty($gambar))
			{
				unlink('./uploads/acara/'.$gambar);
			}
			pesan('Berhasil Menghapus Data',base_url('partner/acara'));
		}else{
			pesan('Gagal Menghapus Data',base_url('partner/acara'));
		}
	}
	
	public function updatepengguna()
	{
		require "./lib/src/skey.php";
		
		$nama = $this->input->post('nama');
		$email = $this->input->post('email');
		$password = $this->input->post('password');
		$password2 = $this->input->post('password2');
		$jk = $this->input->post('jk');
		$tgllahir = $this->input->post('tgllahir');
		
		$mypassword = do_hash($this->input->post('mypassword'));
		$cekuser = $this->partnermodel->cek_user_password($uid, $mypassword);
		
		$chpass = FALSE;
		$deloldgambar = FALSE;
		$gambar = $this->partnermodel->get_data_single('gambar','dn_users','uid',$uid);
		$oldgambar = $gambar;
		
		if($cekuser === TRUE)
		{
			if( ! empty($password) && ! empty($password2))
			{
				if($password === $password2)
				{
					$newpass = do_hash($password);
					$chpass = TRUE;
				}
				else
				{
					pesan('Anda hendak mengubah password tapi kedua password tidak sama!',base_url('partner/edit'));
					exit(0);
				}
			}
			
			if( ! empty ($_FILES['gambar']['name']))
			{
				$config['upload_path'] = './uploads/pengguna/';
				$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
				$config['max_size']	= '1000';
				$config['max_width'] = '1000';
				$config['max_height'] = '1000';
				$config['max_filename'] = '100';
				$this->upload->initialize($config);
				
				if ($this->upload->do_upload('gambar')){
					if($oldgambar != ""){
						$deloldgambar = TRUE;
					}
					
					$udata = $this->upload->data();
					$gambar = $udata['file_name'];
					
				}else{
					
					pesan('Gagal Upload gambar pastikan gambar berekstensi jpg, gif, atau bmp dan tidak lebih dari 1 MB!',base_url('partner/edit'));
					exit(0);
				}
			}
			
			if($chpass === TRUE)
			{
				$data = array('password' => $newpass, 'nama' => $nama, 'email' => $email, 'jk' => $jk, 'tgllahir' => $tgllahir, 'gambar' => $gambar);
			}
			else
			{
				$data = array('nama' => $nama, 'email' => $email, 'jk' => $jk, 'tgllahir' => $tgllahir, 'gambar' => $gambar);
			}
			
			$update = $this->partnermodel->update_user($data, $uid);
			if($update === TRUE)
			{
				if( ! empty($oldgambar) && ($deloldgambar == TRUE))
				{
					unlink('./uploads/pengguna/'.$oldgambar);
				}
				pesan('Data Berhasil diubah',base_url('partner/edit'));
			}
			else
			{
				pesan('Terjadi kesalahan Saat Melakukan update',base_url('partner/edit'));
			}
			
		}
		else
		{
			$this->load->view('partner/editprofile', array('pesan' => 'Password yang anda masukan salah!'));
		}
		
	}
	
	public function kontak()
	{
		$nama = $this->input->post('nama');
		$email = $this->input->post('email');
		$masukan = $this->input->post('masukan');
		$privatekey = "6Le4eNMSAAAAAO2HSWUNnFqlvrksaJVgPsdK6uUr";
		
		# the response from reCAPTCHA
		$resp = null;
		# the error code from reCAPTCHA, if any
		$error = null;

			
		
		if(($nama != null) && ($email != null) && ($masukan != null)){
			
			$this->load->view('lib/recaptchalib',TRUE);
			
			# was there a reCAPTCHA response?
			if ($_POST["recaptcha_response_field"]) {
					$resp = recaptcha_check_answer ($privatekey,
													$_SERVER["REMOTE_ADDR"],
													$_POST["recaptcha_challenge_field"],
													$_POST["recaptcha_response_field"]);

				if ($resp->is_valid) {
						$this->load->library('email');
						

						
						$this->email->from('no-reply@dadannetwork.com');
						$this->email->to('dadan.setia@gmail.com');

						$this->email->subject('Kontak konsumen DadanNetwork');
						$this->email->message($masukan);	

						$this->email->send();
						
						$this->email->from('no-reply@dadannetwork.com');
						$this->email->to($email);

						$this->email->subject('Terima Kasih');
						$this->email->message('Bpk/ibu/saudara/saudari '.$nama.' Pertanyaan, saran, ide kritik, masukan anda akan kami tinjau, Terima Kasih sebelumnya.');	

						$this->email->send();

						echo $this->email->print_debugger();
						
						
						pesan('Terima kasih \nKami akan segera meninjaunya',base_url('main/'));
						
				} else {
						# set the error code so that we can display it
						pesan('Captcha tidak cocok',base_url('main/kontak'));
				}
			}
			
			
		}else{
			pesan('Data Tidak Lengkap',base_url('main/kontak'));
		}
		
	}
	
	public function scplugin()
	{
		include "./lib/src/skey.php";
		
		$sc = $this->input->get('sc');
		$act = $this->input->get('act');
		
		switch($sc)
		{
			case "fb":
				include "./lib/facebook/src/facebook.php";
				include "./lib/src/fbkey.php";
				
				$pesan = "";
				
				if($fbuser)
				{
					$cek = $this->adminmodel->cek_social_network($uid, 'fb');
					$cek2 = $this->adminmodel->cek_social_network_id($sc, $fbuser);
					
					switch($act){
						case "add":
							if($cek !== TRUE)
							{
								$akses = $this->adminmodel->set_social_network($uid, $sc, $fbuser);
								$pesan = "Berhasil Menautkan!";
							}else
							{
								$akses = $akses = $this->adminmodel->update_social_network($uid, $sc, $fbuser);
								$pesan = "Berhasil Menautkan!";
							}
						;
						break;
						
						case "upd":
							if($cek === TRUE)
							{
								$akses = $this->adminmodel->update_social_network($uid, $sc, $fbuser);
								$pesan = "Berhasil Mengubah data!";
							}
							else
							{
								$akses = FALSE;
							}
						;
						break;
						
						case "rmv":
							$akses = $this->adminmodel->update_social_network($uid, $sc, '');
							$pesan = "Akses Akun telah dihentikan";
						;
						break;
						
						default:
							pesan('Terjadi Kesalahan', base_url('otakkanan'));
						;
						break;
						
					}
					
					
					if($akses === TRUE)
					{
						pesan($pesan, base_url('otakkanan'));
					}
					else{
						pesan('Terjadi Kesalahan', base_url('otakkanan'));
					}
					
				}
				else{
					pesan('Terjadi Kesalahan', base_url('otakkanan'));
				}
			;
			break;
			
			case "tw":
				echo "Error not configure";
			;
			break;
			
			case "gp":
				
				require './lib/google/src/Google_Client.php';
				require './lib/google/src/contrib/Google_Oauth2Service.php';
		
				require './lib/src/googlekey.php';
				$pesan = "";
				if(isset ($gpuser))
				{
					$cek = $this->adminmodel->cek_social_network($uid, 'gp');
					
					switch($act){
						case "add":
							if($cek !== TRUE)
							{
								$akses = $this->adminmodel->set_social_network($uid, $sc, $gpuser['id']);
								$pesan = "Berhasil Menautkan!";
							}else
							{
								$akses = $akses = $this->adminmodel->update_social_network($uid, $sc, $gpuser['id']);
								$pesan = "Berhasil Menautkan!";
							}
						;
						break;
						
						case "upd":
							if($cek === TRUE)
							{
								$akses = $this->adminmodel->update_social_network($uid, $sc, $gpuser['id']);
								$pesan = "Berhasil Mengubah data!";
							}
							else
							{
								$akses = FALSE;
							}
						;
						break;
						
						case "rmv":
							$akses = $this->adminmodel->update_social_network($uid, $sc, '');
							$pesan = "Akses Akun telah dihentikan";
						;
						break;
						
						default:
							pesan('Terjadi Kesalahan', base_url('otakkanan'));
						;
						break;
						
					}
					
					
					if($akses === TRUE)
					{
						pesan($pesan, base_url('otakkanan'));
					}
					else{
						pesan('Terjadi Kesalahan', base_url('otakkanan'));
					}
				}
				else{
					pesan('Terjadi Kesalahan', base_url('otakkanan'));
				}
					
			;
			break;
			
			default:
				pesan('Terjadi Kesalahan', base_url('otakkanan'));
			;
			break;
		}
	}
	
	
}

/* End of file partnership.php */
/* Location: ./application/controllers/partnership.php */
